/**
 * PredictionUtilities.java
 * 
 * Contains utility functions to aid in energy prediction. 
 */

package com.swin.energy;

import java.util.Collections;
import java.util.List;

public class PredictionUtilities {

	static public Double calcMedian(List<Double> values) {
		List<Double> myArray = values;
		Collections.sort(myArray);
		int arrayLength = 0;
		double arrayMedian = 0;
		int currentIndex = 0;
		arrayLength = myArray.size();
		if (arrayLength % 2 != 0) {
			currentIndex = ((arrayLength / 2) + 1);
			arrayMedian = myArray.get(currentIndex - 1);
		} else {
			int indexOne = (arrayLength / 2);
			int indexTwo = arrayLength / 2 + 1;
			double arraysSum = myArray.get(indexOne - 1)
					+ myArray.get(indexTwo - 1);
			arrayMedian = arraysSum / 2;
		}
		return arrayMedian;
	}

	static public Double calcMean(List<Double> rawValues) {
		List<Double> myArray = rawValues;
		double arraySum = 0;
		double arrayAverage = 0;
		for (int x = 0; x < myArray.size() - 1; x++)
			arraySum += myArray.get(x);
		arrayAverage = arraySum / myArray.size();
		return arrayAverage;
	}

}
